package fr.cnam.projetSiw.client.structure.pages.description;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

import fr.cnam.projetSiw.client.ressources.GeneralBundle;
import fr.cnam.projetSiw.shared.Artist;

public class DescArtistViewImpl extends Composite implements DescArtistView
{

	@UiField
	HTML lblDesc;


	@UiField
	HTML lblBorn;


	@UiField
	HTML lblGenres;

	@UiField
	HTML titre;

	@UiField
	FlowPanel pnlImage;

	private static DescArtistViewImplUiBinder uiBinder = GWT.create(DescArtistViewImplUiBinder.class);

	interface DescArtistViewImplUiBinder extends UiBinder<Widget, DescArtistViewImpl>
	{
	}

	private Presenter presenter;

	public DescArtistViewImpl()
	{
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setPresenter(ZicPresenter presenter)
	{
		this.presenter = (Presenter) presenter;
	}

	@Override
	public void setData(Artist result)
	{
		if (result == null)
			return;
		titre.setText(result.getName());
		titre.addStyleName(GeneralBundle.INSTANCE.css().titleSquare());
		titre.addStyleName(GeneralBundle.INSTANCE.css().colorBlue());

		lblDesc.setText(result.getDescription());
		if (result.getBirthDate() != null)
			lblBorn.setText(DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM).format(result.getBirthDate()));
		else
			lblBorn.setText("");
		pnlImage.add(new Image(result.getImg()));

		for (String a : result.getGenres())
		{
			if (lblGenres.getText().isEmpty())
				lblGenres.setText(a);
			else
				lblGenres.setText(lblGenres.getText() + "," + a);
		}
	}

}
